Cisco IOS システム管理 – sshサーバの設定とsshコマンドの説明 您所在的位置:网站首页 ssh source interface all Cisco IOS システム管理 – sshサーバの設定とsshコマンドの説明

Cisco IOS システム管理 – sshサーバの設定とsshコマンドの説明

2024-07-12 20:22| 来源: 网络整理| 查看: 265

ルータ機器にsshログインする方法についてまとめます。必要な作業は、鍵作成、ドメイン名設定、ホスト名設定、line vtyに対するssh接続許可などです。

コマンド一覧構成図仕様説明基本設定ポート番号その他基本設定設定投入動作確認AAA 併用設定投入動作確認ポート番号の変更設定投入動作確認その他 機能設定投入動作確認TipsMQCCPP コマンド一覧

このシナリオで重要なコマンド一覧は以下の通りです。

Router(config)# ip domain-name example.com Router(config)# crypto key generate rsa general-keys modulus Router(config)# username privilege password Router(config)# ip ssh port rotary Router(config)# ip ssh logging events Router(config)# ip ssh source-interface Router(config)# Router(config)# line vty 0 4 Router(config-line)# transport input ssh Router(config-line)# login local Router(config-line)# rotary 構成図

以下の構成で動作確認を行います。

e0/0 e0/0 +--------+.1 .2+--------+ | R1 +--------+ R2 | +--------+ +--------+ 192.168.12.0/24 R1 Loopback0 R2 Loopback0 10.1.1.1/32 10.2.2.2/32 [R1] router ospf 1 network 0.0.0.0 255.255.255 area 0 [R2] router ospf 1 network 0.0.0.0 255.255.255 area 0

設定全文は下記ファイルです。詳細設定は下記を参照ください。

R1 ! version 12.4 service timestamps debug datetime msec service timestamps log datetime msec no service password-encryption ! hostname R1 ! boot-start-marker boot-end-marker ! ! no aaa new-model memory-size iomem 5 ! ! ip cef ! ! ip auth-proxy max-nodata-conns 3 ip admission max-nodata-conns 3 ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! interface Loopback0 ip address 10.1.1.1 255.255.255.255 ! interface Ethernet0/0 ip address 192.168.12.1 255.255.255.0 half-duplex ! interface Ethernet0/1 no ip address shutdown half-duplex ! interface Ethernet0/2 no ip address shutdown half-duplex ! interface Ethernet0/3 no ip address shutdown half-duplex ! router ospf 1 log-adjacency-changes network 0.0.0.0 255.255.255.255 area 0 ! ip http server no ip http secure-server ! ip forward-protocol nd ! ! ! ! ! control-plane ! ! ! ! ! ! ! ! ! ! line con 0 line aux 0 line vty 0 4 login ! ! end R2 ! version 12.4 service timestamps debug datetime msec service timestamps log datetime msec no service password-encryption ! hostname R2 ! boot-start-marker boot-end-marker ! ! no aaa new-model memory-size iomem 5 ! ! ip cef ! ! ip auth-proxy max-nodata-conns 3 ip admission max-nodata-conns 3 ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! interface Loopback0 ip address 10.2.2.2 255.255.255.255 ! interface Ethernet0/0 ip address 192.168.12.2 255.255.255.0 half-duplex ! interface Ethernet0/1 no ip address shutdown half-duplex ! interface Ethernet0/2 no ip address shutdown half-duplex ! interface Ethernet0/3 no ip address shutdown half-duplex ! router ospf 1 log-adjacency-changes network 0.0.0.0 255.255.255.255 area 0 ! ip http server no ip http secure-server ! ip forward-protocol nd ! ! ! ! ! control-plane ! ! ! ! ! ! ! ! ! ! line con 0 line aux 0 line vty 0 4 login ! ! end 仕様説明 基本設定

sshログインを可能にするために最低限必要な設定は、ドメイン名の設定とssh keyの作成です。もしssh version2を利用したいならば、鍵長は768bit以上にする必要があります。

Router(config)# ip domain-name example.com Router(config)# crypto key generate rsa general-keys modulus

Cisco IOSはデフォルトでユーザが存在しないので、sshログイン用のユーザを作成します。またline vtyに対してsshログインを許可し、さらに認証方式をローカルユーザに変更します。

Router(config)# username privilege password Router(config)# Router(config)# line vty 0 4 Router(config-line)# transport input ssh Router(config-line)# login local ポート番号

telnetと異なりsshはrotaryの設定のみで3001, 4001, 5001などのポートで待ちける事ができません。sshのポート番号を変更する場合は、lineに対してrotaryを設定し、rotaryと紐づくtcp portを定義します。

Router(config)# line vty 0 4 Router(config-line)# rotary Router(config)# Router(config)# ip ssh port rotary その他

以下のコマンドでsshログインに関するイベントをログ出力できます。

Router(config)# ip ssh logging events

以下のコマンドでssh接続する際の送信元I/Fを定義する事ができます。

Router(config)# ip ssh source-interface 基本設定 設定投入

R2からR1へssh接続が可能になるよう設定します。

[R1] username root privilege 15 password Cisco username user password Cisco ! ip domain-name example.com crypto key generate rsa general-keys modulus 768 ! line vty 0 4 transport input ssh login local 動作確認

R2からR1へsshログインが可能である事を確認します。

[R1] R2#ssh -l root 10.1.1.1 Password: R1# AAA 併用 設定投入

AAAを併用したsshの設定例は以下の通りです。なお、“local”と”local-case”とは明確に区別されており、パスワードの大文字小文字を区別する場合は”local-case”を指定します。

[R1] aaa authentication login VTY local-case aaa authorization exec VTY local ! line vty 0 4 login authentication VTY authorization exec VTY 動作確認

R2からR1へsshログインが可能であり、想定通りのprivilegeが付与されている事を確認します。

[R2] R2#ssh -l user 10.1.1.1 Password: R1>show privilege Current privilege level is 1 R1>exit [Connection to 10.1.1.1 closed by foreign host] R2# R2# R2#ssh -l root 10.1.1.1 Password: R1#show privilege R1#show privilege Current privilege level is 15 R1# ポート番号の変更 設定投入

sshを待ち受けるポート番号を2022に変更します。

[R1] line vty 0 4 rotary 1 ! ip ssh port 2022 rotary 1 動作確認

変更後のポート番号でR2からR1へsshログインが可能である事を確認します。

[R2] R2#ssh -l root -p 2022 10.1.1.1 Password: R1# その他 機能 設定投入

R1に”ip ssh logging events”コマンドを投入し、sshに関するイベントをログ出力するようにします。また、R2に”ip ssh source-interface”コマンドを投入し、ssh接続する際の送信元I/FをLoopback0に固定します。

[R1] ip ssh logging events [R2] ip domain-name example.com crypto key generate rsa general-keys modulus 768 ip ssh source-interface Loopback 0 動作確認

R2からR1へのsshログインを試みます。R1にはsshに関するログ出力があり、また送信元がR2 lo0(10.2.2.2)に変わっている事を確認します。

[R2] R2#ssh -l root -p 2022 10.1.1.1 Password: R1# [R1] R1# *Mar 1 00:27:13.331: %SSH-5-SSH2_SESSION: SSH2 Session request from 10.2.2.2 (tty = 0) using crypto cipher 'aes128-cbc', hmac 'hmac-sha1' Succeeded *Mar 1 00:27:14.887: %SSH-5-SSH2_USERAUTH: User 'root' authentication for SSH2 Session from 10.2.2.2 (tty = 0) using crypto cipher 'aes128-cbc', hmac 'hmac-sha1' Succeeded R1# R1#show tcp br R1#show tcp brief TCB Local Address Foreign Address (state) 64BA8FE0 10.1.1.1.2022 10.2.2.2.45230 ESTAB R1# Tips MQC

CCIE R&Sに出題されるようなトラブルシューティングの出題例を紹介します。例えば、以下のようにMQCが設定されり、Loopback経由のsshログイン不能になるようなトラブルシューティングが出題されます。

[R1] no ip ssh port 2022 rotary 1 ! access-list 1 permit 10.0.0.0 0.255.255.255 ! class-map SSH match protocol ssh match access-group 1 ! policy-map POLICE class SSH police 8000 conform-action drop ! interface Ethernet 0/0 service-policy input POLICE

Loopback0を経由したログインが不能である事を確認します。

[R2] R2(config)#ip ssh source-interface Loopback 0 R2(config)#do ssh -l root 10.1.1.1 R2(config)# R2(config)#no ip ssh source-interface Loopback 0 R2(config)#do ssh -l root 10.1.1.1 Password: R1# [R1] R1#show policy-map interface Ethernet0/0 Service-policy input: POLICE Class-map: SSH (match-all) 4 packets, 240 bytes 5 minute offered rate 0 bps, drop rate 0 bps Match: protocol ssh Match: access-group 1 POLICE: cir 8000 bps, bc 1500 bytes conformed 4 packets, 240 bytes; actions: drop exceeded 0 packets, 0 bytes; actions: drop conformed 0 bps, exceed 0 bps Class-map: class-default (match-any) 129 packets, 11376 bytes 5 minute offered rate 0 bps, drop rate 0 bps Match: any R1# CPP

Control Plane Policingによる疎通不能であるパターンもよく出題されます。例えば、以下のような設定になっていますと、Loopback経由のsshログイン不能になります。

[R1] interface Ethernet 0/0 no service-policy input POLICE no policy-map POLICE no class-map SSH no access-list 1 ! access-list 100 permit tcp host 10.2.2.2 any eq 22 ! class-map SSH match access-group 100 ! policy-map POLICE class SSH police 8000 conform-action drop ! control-plane service-policy input POLICE

Loopback0を経由したログインが不能である事を確認します。

[R2] R2(config)#ip ssh source-interface Loopback 0 R2(config)#do ssh -l root 10.1.1.1 R2(config)# R2(config)#no ip ssh source-interface Loopback 0 R2(config)#do ssh -l root 10.1.1.1 Password: R1# [R1] R1#show policy-map control-plane Control Plane Service-policy input: POLICE Class-map: SSH (match-all) 4 packets, 240 bytes 5 minute offered rate 0 bps, drop rate 0 bps Match: access-group 100 police: cir 8000 bps, bc 1500 bytes conformed 4 packets, 240 bytes; actions: drop exceeded 0 packets, 0 bytes; actions: drop conformed 0 bps, exceed 0 bps Class-map: class-default (match-any) 120 packets, 11524 bytes 5 minute offered rate 1000 bps, drop rate 0 bps Match: any R1#


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有